from flask import *

app = Flask(__name__)

app.config["SECRET_KEY"] = 'qdddd!=kt_8c*ohm$3k+hhhhejx&+=4avs#-a6+#@@'


@app.route("/set_cookie")
def set_cookie():
    # response
    res = make_response("OK")
    res.set_cookie("name", "zyd", max_age=100)
    return res


@app.route("/get_cookie")
def get_cookie():
    cookie = request.cookies
    return cookie


@app.route("/del_cookie")
def del_cookie():
    res = make_response(render_template("data.html"))
    res.delete_cookie("name")
    return res


@app.route("/set_session")
def set_session():
    session['name'] = 'zyd'
    return "<h1>set_session</h1>"


@app.route("/get_session")
def get_session():
    dic = {}
    dic['name'] = session.get('name')
    return jsonify(dic)


@app.route("/del_session")
def del_session():
    name = session.pop("name")
    # session.clear() # 清除所有的session信息
    return name


if __name__ == '__main__':
    app.run(debug=True)
